{% extends 'layout/basic.html' %}
{% load static %}
{% block title %}用户登录{% endblock %}
{% block css %}
    <link rel="stylesheet" href="{% static 'css/register_login.css' %}">
{% endblock %}
{% block content %}
    <div class="reg">
        <h1 class="title">用户登录</h1>
        <form id="regForm" method="POST">
            {% for field in form %}
                {% if field.name == 'code' %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        <div class="row">
                            <div class="col-xs-7">
                                {{ field }}
                                <span class="error-msg">{{ field.errors.0 }}</span>
                            </div>
                            <div class="col-xs-5" style="cursor: pointer">
                                <img src="{% url 'app:login_code' %}" alt="" id="login_code">
                            </div>
                        </div>
                    </div>
                {% else %}
                    <div class="form-group">
                        <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                        {{ field }}
                        <span class="error-msg">{{ field.errors.0 }}</span>
                    </div>
                {% endif %}
            {% endfor %}
            <button type="submit" class="btn btn-primary">登 录</button>
            <a href="{% url 'app:login_sms' %}" style="display: inline-block;text-decoration: none;float: right">短信验证码登录</a>
        </form>
    </div>
{% endblock %}
{% block js %}
    <script>
        $(function () {
            changeCode();
        })

        function changeCode() {
            $('#login_code').click(function () {
                let old_src = $(this).attr('src');
                $(this).attr('src', old_src + '?')
            })
        }

    </script>
{% endblock %}